var db        = exports;

var Mongolian = require("mongolian");
var eyes      = require('eyes');

// Config
var host            = "staff.mongohq.com"
var port            = 10094
var databaseName    = "midgard"
var username        = "stariebucks";
var password        = "stariebucks2012";

// Set up server
var server          = new Mongolian(host+":"+port);
var dbc             = server.db(databaseName);
dbc.auth(username, password);

// Collections
db.projects  = dbc.collection("projects");
db.users     = dbc.collection("users");

// Methods
db.getUser = function (data, callback) {
    var username    = data.user.name;
    var password    = data.user.password;
    eyes.inspect(data, "db#getUser() data");

    db.users.findOne({ username: username, password: password},
        function(err, user) {
            if (err) throw err;
            callback(err, user);
        }
    );
};

db.getProjects = function (data, callback) {
    var projectDate    = data.project.date;
    var projectPhase   = data.project.phase;
    eyes.inspect(data, "db#getProjects data");

    db.projects.find({date: projectDate, phase: projectPhase},
        function(err, project) {
            if (err) throw err;
            callback(err, project);
        }
    );
};